<?php 
/**
* filter class structOutput
* type: output
* return: object
*/

class filterStructOutput extends bookstoreOutputFilter{


	function __construct(){
		$this->type = 'output';
		$this->name = 'structOutput';
	}//end constructor

	/**
	* reorganize db obj to emulate existing booksite term query
	* input is an db obj(returned from model->queryDb())
	*/
	
	function filter($return_type = '',&$input){
	
		foreach($input as $key=>$value){
			
			if(!empty($value)){
				foreach($value as $k=>$v){
					if($k == 'title' && strlen($v) > 60){
						$v = substr($v,0,57).'...';
					}
					$filtered_input->result_set[$key]->sq1->details[0]->$k = ucwords(strtolower($v));
					$filtered_input->result_set[$key]->$k = ucwords(strtolower($v));
					
				}//end of foreach in detail
				
				//$filtered_input->result_set[$key]->sq1->details[0] = $value;
				$filtered_input->result_set[$key]->sq1->instore->total_avail = $value->avail_for_sale;
			}else{ 
				/**
				* NOTE: here 'NIS' stands for Never In Stock; in SQ1, it only means Not In Stock;
				*/
				$filtered_input->result_set[$key]->sq1->details[0] = $value;
				$results =new stdclass();
				$filtered_input->result_set[$key]->sq1->instore = new stdclass();
				$filtered_input->result_set[$key]->sq1->instore->flag = (string)'NIS';
				$filtered_input->result_set[$key]->sq1->instore->total_avail = (int)'0';
			}//end if results
		//	$filtered_input->result_set[$key] = $value;
		//	$filtered_input->result_set[$key]->sq1 = $results;
		}//end foreach
		
		return $filtered_input;
		
	}//end filter method
	
}//end filterStructOutput class

?>
